home *** CD-ROM | disk | FTP | other *** search
- class smashing.sound.SoundEngine
- {
- var __mc;
- var o_sounds;
- var o_groups;
- var __a_soundQueue;
- var __flag_muted;
- var __flag_overwrite;
- var __groupCount;
- var __callbackPath;
- var __callbackFunc;
- var myName;
- var owner;
- var onSoundComplete;
- var cbpath;
- var __DEFAULTMCNAME = "soundEngine_MC";
- var __DEFAULTGROUPNAME = "sound";
- function SoundEngine()
- {
- }
- function generateSounds(t_path, t_depth, t_overwrite)
- {
- this.__mc = t_path.createEmptyMovieClip(this.__DEFAULTMCNAME,t_depth);
- this.o_sounds = {};
- this.o_groups = {};
- this.__a_soundQueue = [];
- this.__flag_muted = false;
- if(t_overwrite == undefined)
- {
- t_overwrite = false;
- }
- this.__flag_overwrite = t_overwrite;
- this.__groupCount = 0;
- this.createGroup(this.__DEFAULTGROUPNAME);
- trace("-- Init Sound Engine -- ");
- }
- function setCallback(path, func)
- {
- this.__callbackPath = path;
- this.__callbackFunc = func;
- }
- function createGroup(t_name)
- {
- this.__groupCount = this.__groupCount + 1;
- var _loc2_ = this.__mc.createEmptyMovieClip(t_name,this.__groupCount);
- _loc2_.soundObject = new Sound(_loc2_);
- this.o_groups[t_name] = _loc2_;
- }
- function createSound(t_name, t_assetID, t_groupName, doCallback)
- {
- var _loc4_ = undefined;
- if(t_groupName == undefined || t_groupName == "" || t_groupName == null)
- {
- _loc4_ = this.o_groups[this.__DEFAULTGROUPNAME];
- }
- else
- {
- _loc4_ = this.o_groups[t_groupName];
- }
- if(_loc4_ != undefined)
- {
- var _loc2_ = {};
- _loc2_.soundEffect = new Sound(_loc4_);
- _loc2_.soundEffect.attachSound(t_assetID);
- if(doCallback == undefined)
- {
- doCallback = false;
- }
- _loc2_.doCallback = doCallback;
- this.o_sounds[t_name] = _loc2_;
- }
- else
- {
- trace("Error Locating Group " + t_groupName + " for create Sound");
- }
- }
- function playSound(t_soundName, t_loops, t_queued)
- {
- if(this.__flag_muted)
- {
- return undefined;
- }
- var _loc2_ = this.o_sounds[t_soundName];
- if(_loc2_ != undefined)
- {
- if(t_loops == undefined)
- {
- t_loops = 1;
- }
- else if(t_loops == 0)
- {
- t_loops = 100000;
- }
- if(this.__flag_overwrite)
- {
- _loc2_.soundEffect.stop();
- }
- if(t_queued == true)
- {
- this.__a_soundQueue[0].doCallback = _loc2_.doCallback;
- _loc2_.soundEffect.onSoundComplete = mx.utils.Delegate.create(this,this.onQueuedSoundComplete);
- }
- else if(_loc2_.doCallback)
- {
- _loc2_.soundEffect.owner = this;
- _loc2_.soundEffect.myName = t_soundName;
- _loc2_.soundEffect.onSoundComplete = function()
- {
- this.owner.onCallbackSoundComplete(this.myName);
- };
- }
- _loc2_.soundEffect.start(0,t_loops);
- }
- else
- {
- trace("Error - sound " + t_soundName + " not found");
- }
- }
- function stopSound(t_soundName)
- {
- this.o_sounds[t_soundName].soundEffect.stop();
- }
- function stopAll()
- {
- this.clearQueue();
- stopAllSounds();
- }
- function changeVolume(t_vol, t_groupName)
- {
- if(t_groupName == undefined)
- {
- t_groupName = this.__DEFAULTGROUPNAME;
- }
- this.o_groups[t_groupName].soundObject.setVolume(t_vol);
- }
- function toggleSound()
- {
- if(this.__flag_muted)
- {
- this.soundOn();
- }
- else
- {
- this.soundOff();
- }
- return !this.__flag_muted;
- }
- function soundOff()
- {
- this.__flag_muted = true;
- }
- function soundOn()
- {
- this.__flag_muted = false;
- }
- function callbackSound(t_soundName, t_loops, path, func)
- {
- this.playSound(t_soundName,t_loops,false);
- var _loc2_ = this.o_sounds[t_soundName];
- _loc2_.soundEffect.cbpath = path;
- _loc2_.soundEffect.cbfunc = func;
- _loc2_.soundEffect.onSoundComplete = function()
- {
- this.onSoundComplete = null;
- this.cbpath[func]();
- };
- }
- function onCallbackSoundComplete(name)
- {
- this.__callbackPath[this.__callbackFunc](name);
- }
- function queueSound(t_soundName, t_isMusic)
- {
- if(t_isMusic == undefined)
- {
- t_isMusic = false;
- }
- this.__a_soundQueue.push({soundName:t_soundName,isMusic:t_isMusic,isPlaying:false,doCallback:false});
- this.__playQueue();
- }
- function __playQueue()
- {
- if(this.__a_soundQueue.length == 0)
- {
- return undefined;
- }
- if(!this.__a_soundQueue[0].isPlaying)
- {
- if(this.__a_soundQueue[0].isMusic == true)
- {
- this.playMusic(this.__a_soundQueue[0].soundName);
- this.clearQueue();
- }
- else
- {
- this.playSound(this.__a_soundQueue[0].soundName,1,true);
- this.__a_soundQueue[0].isPlaying = true;
- }
- }
- }
- function onQueuedSoundComplete()
- {
- if(this.__a_soundQueue[0].doCallback)
- {
- this.onCallbackSoundComplete(this.__a_soundQueue[0].soundName);
- }
- this.__a_soundQueue.splice(0,1);
- trace("Finish sound");
- this.__playQueue();
- }
- function clearQueue()
- {
- this.__a_soundQueue = [this.__a_soundQueue[0]];
- }
- function get queueLength()
- {
- return this.__a_soundQueue.length;
- }
- function playMusic(name)
- {
- }
- function get isQueuePlaying()
- {
- if(this.__a_soundQueue.length == 0)
- {
- return false;
- }
- return true;
- }
- }
-